package com.lehuowujie.lehuomarket.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lehuowujie.lehuomarket.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 王瑞铭 on 2017/1/13.
 */
public class CategoryLeftAdapter extends BaseAdapter {

    private List<String> mList = new ArrayList<>();
    private LayoutInflater mInflater;
    private static int mCurrentPosition;

    public CategoryLeftAdapter(Context context, List<String> list) {
        this.mList = list;
        this.mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            holder = new ViewHolder();
            view = mInflater.inflate(R.layout.item_category_left_layout, viewGroup, false);
            holder.categoryName = (TextView) view.findViewById(R.id.categoryName);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.categoryName.setTextColor(Color.BLACK);
        holder.categoryName.setBackgroundResource(R.color.white);
        holder.categoryName.setText(mList.get(i));
        if (mCurrentPosition == i)
        {
            holder.categoryName.setTextColor(Color.RED);
            holder.categoryName.setBackgroundResource(R.color.background);
        }
        return view;
    }

    public void setSelectPosition(int position)
    {
        this.mCurrentPosition = position;
    }

    private class ViewHolder {
        TextView categoryName;
    }
}
